package com.witmore.skyline.web.constants;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class TableSortCustomConstant {

    /**
     * 允许排序的字段
     */
    public static final Set<String> CAMERA_ALLOWED_SORT_FIELDS = Set.of("createTime", "cameraStatus");

    public static final Set<String> ALLOWED_SORT_ORDER = Set.of("ASC", "DESC");


    /**
     * 允许排序的字段
     */
    private static final Map<String, String> FIELD_MAPPING_CAMERA = new HashMap<>();

    static {

        // 摄像头表
        FIELD_MAPPING_CAMERA.put("cameraStatus", "camera_status");
        FIELD_MAPPING_CAMERA.put("createTime", "create_time");


    }


    // ------------------------------------------------ skyline_camera 表搜索字段---------------------------------------------
    public static Map<String, String> convertToDbFieldCamera(String camelSortField, String cameraSortOrder) {
        String dbSortField = FIELD_MAPPING_CAMERA.get("createTime");
        String dbSortOrder = "DESC";

        // 先规范入参
        if (StringUtils.isNotEmpty(camelSortField) && StringUtils.isNotEmpty(cameraSortOrder)) {
            if (CAMERA_ALLOWED_SORT_FIELDS.contains(camelSortField)) {
                dbSortField = FIELD_MAPPING_CAMERA.get(camelSortField);
            }
            String upperCase = cameraSortOrder.toUpperCase();
            if (ALLOWED_SORT_ORDER.contains(upperCase)) {
                dbSortOrder = cameraSortOrder;
            }
        }
        return Map.of("dbSortField", dbSortField, "dbSortOrder", dbSortOrder);

    }
    // ------------------------------------------------ skyline_camera 表搜索字段---------------------------------------------

}
